package com.kk.license.server;

import com.alibaba.fastjson2.JSON;
import com.kk.license.common.bean.LicenseCheckModel;
import com.kk.license.server.util.KeytoolUtils;
import com.kk.license.server.util.LicenseUtils;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Base64;
import java.util.Scanner;

@SpringBootApplication
public class LicenseServerApplication {

    public static void main(String[] args) {
        //生成私钥
        KeytoolUtils.generatePrivateKey();
        //将公钥导出至临时文件
        KeytoolUtils.generateCertFile();
        //生成公钥
        KeytoolUtils.generatePublicKey();

        //等待输入机器码
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入授权机器码");
        String s= scanner.nextLine();
        scanner.close();

        //将机器码转换为授权参数对象
        byte[] decode = Base64.getDecoder().decode(s);
        LicenseCheckModel licenseCheckModel = JSON.parseObject(decode).toJavaObject(LicenseCheckModel.class);

        //设置允许添加设备通道数
        licenseCheckModel.setAllowChannel(555);

        //生成证书
        LicenseUtils.generateLicense(s);
    }

}
